(defun c:door()
  
  (command "layer""m""door""c"2"" "")
  (setq dtype (getstring "\nTop,Bout,Left,Right,Ucs :"))
  (setq dtype (strcase dtype))
  (setq p1 (getpoint "\nGet first point :"))
  (setq p2 (getpoint p1 "\nGet secound point :"))
  
  (setq ang (angtos (angle p1 p2 ) 0 2 )
  )
   
  (if (= dtype "U") (temp) )
  
  (if (and (= dtype "T") (< (car p1) (car p2))
      ) (topr))
  (if (and (= dtype "T") (> (car p1) (car p2))
      ) (topl))
  
  (if (and (= dtype "B") (< (car p1) (car p2))
      ) (boutr))
  (if (and (= dtype "B") (> (car p1) (car p2))
      ) (boutl))
  
  (if (and (= dtype "L") (< (cadr p1) (cadr p2))
      ) (leftu))
  
  (if (and (= dtype "L") (> (cadr p1) (cadr p2))
      ) (leftd))
  
  (if (and (= dtype "R") (< (cadr p1) (cadr p2))
      ) (rightu))
  
  (if (and (= dtype "R") (> (cadr p1) (cadr p2))
      ) (rightd))


)
 
 (defun topr()
   (command "insert" "ch-doorl" p1 "1" "1" "")
   (command "insert" "ch-doorr" p2 "1" "1" "")
   
   (setq p1 (mapcar '+ p1 '(0.045 0.07 0))
   )
   

   (setq p2 (list (- (car p2) 0.02) (+ (cadr p2) 0.06) 0
            )
   )  
   
   
   (setq p4 (distance p1 p2))

   (setq p3 (list (car p1) (+ (cadr p1) p4) 0
            )
   )
   
   (command "trace""0.03" p1 p3"")
   
   (command "arc" p2 "c" p1 p3)
   (command "ucs" "w" )
 )
 
 (defun topl()
   
   (command "insert" "ch-doorr" p1 "1" "1" "")
   (command "insert" "ch-doorl" p2 "1" "1" "")
   
   (setq p1 (list (- (car p1) 0.045) (+ (cadr p1) 0.07) 0 
            )
   )

   (setq p2 (list (+ (car p2) 0.02) (+ (cadr p2) 0.06) 0
            )
   )  
   
   
   (setq p4 (distance p1 p2))

   (setq p3 (list (car p1) (+ (cadr p1) p4) 0
            )
   )
   
   (command "trace""0.03" p1 p3"")
   
   (command "arc" p3 "c" p1 p2)
   
   (command "ucs" "w" )
 )
 
 
 (defun boutr()
   
   (command "insert" "ch-doorr" p1 "1" "1" "180")
   (command "insert" "ch-doorl" p2 "1" "1" "180")
   

   (setq p1 (list (+ (car p1) 0.045) (- (cadr p1) 0.07) 0 
            )
   )


   (setq p2 (list (- (car p2) 0.02) (- (cadr p2) 0.06) 0
            )
   )  

   (setq p4 (distance p1 p2))

   (setq p3 (list (car p1) (- (cadr p1) p4) 0
            )
   )
   
   (command "trace""0.03" p1 p3"")
   
   (command "arc" p3 "c" p1 p2)
 
   (command "ucs" "w" )
 )
 
 
 (defun boutl()
   
   (command "insert" "ch-doorl" p1 "1" "1" "180")
   (command "insert" "ch-doorr" p2 "1" "1" "180")
   

   (setq p1 (list (- (car p1) 0.045) (- (cadr p1) 0.07) 0 
            )
   )


   (setq p2 (list (+ (car p2) 0.02) (- (cadr p2) 0.06) 0
            )
   )  

   (setq p4 (distance p1 p2))

   (setq p3 (list (car p1) (- (cadr p1) p4) 0
            )
   )
   
   (command "trace""0.03" p1 p3"")
   
   (command "arc" p2 "c" p1 p3)
   
   (command "ucs" "w" )
 )
 

 (defun leftu()
   
   (command "insert" "ch-doorl" p1 "1" "1" "90")
   (command "insert" "ch-doorr" p2 "1" "1" "90")
   
   (setq p1 (list (- (car p1) 0.07) (+ (cadr p1) 0.045 ) 0 
            )
   )


   (setq p2 (list (- (car p2) 0.06) (- (cadr p2) 0.02) 0
            )
   )  

   (setq p4 (distance p1 p2))

   (setq p3 (list (- (car p1) p4 ) (cadr p1) 0
            )
   )
   
   (command "trace""0.03" p1 p3"")
   
   (command "arc" p2 "c" p1 p3)
   
   (command "ucs" "w" )
 )
 
 

 (defun leftd()
   
   (command "insert" "ch-doorr" p1 "1" "1" "90")
   (command "insert" "ch-doorl" p2 "1" "1" "90")
   
   (setq p1 (list (- (car p1) 0.07) (- (cadr p1) 0.045 ) 0 
            )
   )


   (setq p2 (list (- (car p2) 0.06) (+ (cadr p2) 0.02) 0
            )
   )  

   (setq p4 (distance p1 p2))

   (setq p3 (list (- (car p1) p4 ) (cadr p1) 0
            )
   )
   
   (command "trace""0.03" p1 p3"")
   
   (command "arc" p3 "c" p1 p2)
   
   (command "ucs" "w" )
 )
 
 (defun rightu()
   
   (command "insert" "ch-doorr" p1 "1" "1" "-90")
   (command "insert" "ch-doorl" p2 "1" "1" "-90")
   
   (setq p1 (list (+ (car p1) 0.07) (+ (cadr p1) 0.045 ) 0 
            )
   )


   (setq p2 (list (+ (car p2) 0.06) (- (cadr p2) 0.02) 0
            )
   )  

   (setq p4 (distance p1 p2))

   (setq p3 (list (+ (car p1) p4 ) (cadr p1) 0
            )
   )
   
   (command "trace""0.03" p1 p3"")
   
   (command "arc" p3 "c" p1 p2)
   
   (command "ucs" "w" )
 )
 
 (defun rightd()
   
   (command "insert" "ch-doorl" p1 "1" "1" "-90")
   (command "insert" "ch-doorr" p2 "1" "1" "-90")
   
   (setq p1 (list (+ (car p1) 0.07) (- (cadr p1) 0.045 ) 0 
            )
   )


   (setq p2 (list (+ (car p2) 0.06) (+ (cadr p2) 0.02) 0
            )
   )  

   (setq p4 (distance p1 p2))

   (setq p3 (list (+ (car p1) p4 ) (cadr p1) 0
            )
   )
   
   (command "trace""0.03" p1 p3"")
   
   (command "arc" p2 "c" p1 p3)
   
   (command "ucs" "w" )
  )
  
  
  (defun temp()
    
    (command "ucs" "z" ang )
  
  (setq dtype (getstring "\nTop,Bout,Left,Right,Ucs :"))
  (setq dtype (strcase dtype))
  (setq p1 (getpoint "\nGet first point :"))
  (setq p2 (getpoint p1 "\nGet secound point :"))
  
  )        
  


